import pymysql
from fastapi import FastAPI,HTTPException,Form
app=FastAPI()
db={
    "host":"127.0.0.1",
    "user":"root",
    "password":"123456Aa",
    "database":"2305a",
    "charset":"utf8"
}
@app.post('/chaxun')
def chaxun(
    employee_name:str=Form(...),
    attendance_status:str=Form(...)
):
    try:
        con=pymysql.Connect(**db)
        cur=con.cursor()
        if employee_name=='':
            raise HTTPException(status_code=409,detail='用户名不能为空')
        if attendance_status=='':
            raise HTTPException(status_code=409,detail='日期不能为空')
        cur.execute('select * from attendance where employee_name=%s or attendance_status=%s',(employee_name,attendance_status))
        con.commit()
        jieguo=cur.fetchone()
        if jieguo:
            return{
                "a":jieguo[0],
                "b":jieguo[1],
                "c":jieguo[2],
                "d":jieguo[3]
         }
    finally:
        con.close()
        cur.close()    